#define _CRT_SECURE_NO_WARNINGS 1
#include<cctype>
class Solution {
public:
    string reverseOnlyLetters(string s) {
        int des = 0;
        int src = s.size() - 1;
        while (des < src)
        {
            if (isalpha(s[des]) && isalpha(s[src]))
            {
                auto tem = s[des];
                s[des] = s[src];
                s[src] = tem;
                des++;
                src--;
            }
            else if (!isalpha(s[des]) && isalpha(s[src]))
            {
                des++;
            }
            else if (isalpha(s[des]) && !isalpha(s[src]))
            {
                src--;
            }
            else
            {
                des++;
                src--;
            }
        }
        return s;
    }
};